package com.zwd.cases.demo.gof23.strategy.cash;

/**
 * @Description 返利折扣子类，初始化时必须输入返利条件和返利值，比如满300返100，则 moneyCondition 为300，moneyReturn 为100
 * @Author zhengwd
 * @Date 2023/4/12 14:43
 **/
public class CashReturn extends CashSuper {

    /**
     *返利条件
     */
    private double moneyCondition;

    /**
     *返利值
     */
    private double moneyReturn;

    public CashReturn(double moneyCondition, double moneyReturn) {
        this.moneyCondition = moneyCondition;
        this.moneyReturn = moneyReturn;
    }

    @Override
    public double acceptCash(double money) {
        double result = money;
        // 当大于返利条件时，则需要减去返利值
        if (money >= moneyCondition) {
            result = money - Math.floor(money / moneyCondition) * moneyReturn;
        }
        return result;
    }
}
